The dynamic equations of spacecraft formation flying are weakly nonlinear equations since the distance between spacecrafts is quite small compared with the orbital radius of the spacecrafts. To solve weakly nonlinear equations effectively, a precise exponential integrator (PEI) was proposed. Precise integration method (PIM) was applied to calculate exponential function in the formulas of exponential integrators (EI). Firstly, PEI was validated by solving a weakly nonlinear equation compared with Runge-Kutta method. Secondly, the dynamic equations of spacecraft formation flying were obtained through Lagrange equations, and then the equations were tansfered into semi-linear form. Ultimately, PEI and Runge-Kutta method were comparatively used to solve these equations. Through numerical analysis, PEI gave higher precision of the dynamic equations of spacecraft formation flying, indicating that PEI can be applied to other weakly nonlinear problems as well.